package com.li.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.logging.Logger;

/**
 * @Author: LiXiang
 * @Description :  Http访问注解
 * @Date: Created in 2018/9/9 19:47
 */
@Aspect
@Component
public class HttpAspect {

    private final static Logger logger = null;
    static {}
    ///////////////////////////业务层log

    @Pointcut("execution(public * com.li.demo.**.*(..))")
    public void log(){

    }

    /**
     * 方法前
     * @Author:  LiXiang
     * @Date: Created in 2018/9/9 19:49
     */
    @Before("log()")
    public void before(JoinPoint joinPoint){

        ServletRequestAttributes attributes =
                (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();

        //访问路径
        request.getRequestURI();

        //方法
        request.getMethod();

        //ip
        request.getRemoteAddr();

        //类方法
        joinPoint.getSignature().getDeclaringTypeName();
        joinPoint.getSignature().getDeclaringType();

        //参数
        joinPoint.getArgs();

        //参数
    }

    @After("log()")
    public void doAfter(){

    }

    @AfterReturning(returning = "obj",pointcut = "log()")
    public void doAfterReturning(Object obj){

    }
}
